package com.up.upzl.biz.service.impl;

import java.io.IOException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.apache.http.client.fluent.Request;
import org.apache.http.client.fluent.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.repository.support.PageableExecutionUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Joiner;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.up.upzl.base.service.impl.BaseServiceImpl;
import com.up.upzl.biz.domain.Shop;
import com.up.upzl.biz.domain.Shop.CreateType;
import com.up.upzl.biz.domain.Shop.ShopAudit;
import com.up.upzl.biz.domain.Shop.ShopFlow;
import com.up.upzl.biz.domain.Shop.Type;
import com.up.upzl.biz.repository.ShopRepository;
import com.up.upzl.biz.service.AreaService;
import com.up.upzl.biz.service.ShopBusinessTypeService;
import com.up.upzl.biz.service.ShopService;
import com.up.upzl.biz.vo.PageWrapper;

import utils.UpzlUtils;

@Service
public class ShopServiceImpl extends BaseServiceImpl<Shop, Long> implements ShopService {

	private Logger log = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private ShopRepository shopRepository;
	@Autowired
	private ShopBusinessTypeService shopBusinessTypeService;

	@Value("${up.crawler.server}")
	private String crawlerServer;

	private ObjectMapper objectMapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
			false);

	private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");

	@Override
	public List<Shop> fetchByCondition(String siteCode, Long[] ids, String source, String areatext, Shop.Type shopType,
			String manageBusinessType, String name, Date beginTime, Date endTime) {
		List<Shop> shops = null;
		try {
			List<String> params = Lists.newArrayList();
			if (!Strings.isNullOrEmpty(siteCode)) {
				params.add("siteCode=" + siteCode);
			}
			if (ids != null) {
				params.add("ids=" + Joiner.on(",").join(Lists.newArrayList(ids)));
			}
			if (!Strings.isNullOrEmpty(source)) {
				params.add("source=" + source);
			}
			if (!Strings.isNullOrEmpty(areatext)) {
				params.add("areatext=" + URLEncoder.encode(areatext, "UTF-8"));
			}
			if (shopType != null) {
				params.add("shopType=" + URLEncoder.encode(shopType.name(), "UTF-8"));
			}
			if (!Strings.isNullOrEmpty(manageBusinessType)) {
				params.add("manageBusinessType=" + URLEncoder.encode(manageBusinessType, "UTF-8"));
			}
			if (!Strings.isNullOrEmpty(name)) {
				params.add("name=" + URLEncoder.encode(name, "UTF-8"));
			}
			if (beginTime != null) {
				params.add("beginTime=" + URLEncoder.encode(sdf.format(beginTime), "UTF-8"));
			}
			if (endTime != null) {
				params.add("endTime=" + URLEncoder.encode(sdf.format(endTime), "UTF-8"));
			}
			Response response = get(crawlerServer + "shop/fetchByCondition"
					+ (params.isEmpty() ? "" : "?" + Joiner.on("&").join(params)));

			shops = objectMapper.readValue(response.returnContent().asString(), new TypeReference<List<Shop>>() {
			});

		} catch (Exception e) {
			log.error("导入数据异常", e);
		}

		return shops;
	}

	/**
	 * ly
	 * 
	 * @param siteCode
	 * @param ids
	 * @return 通过ids把数据存入数据库中
	 */
	@Override
	public List<Shop> shopIds(String siteCode, String ids) {
		List<Shop> shops = null;
		try {
			List<String> params = Lists.newArrayList();
			if (!Strings.isNullOrEmpty(siteCode)) {
				params.add("siteCode=" + siteCode);
			}
			if (!Strings.isNullOrEmpty(ids)) {
				params.add("ids=" + ids);
			}
			Response response = get(
					crawlerServer + "shop/callback" + (params.isEmpty() ? "" : "?" + Joiner.on("&").join(params)));
			shops = objectMapper.readValue(response.returnContent().asString(), new TypeReference<List<Shop>>() {
			});
		} catch (Exception e) {
			log.error("通知异常", e);
		}
		return shops;
	}

	/**
	 * 请求API
	 */
	@Override
	public Page<Shop> list(Boolean status, String siteCode, String source, String areaText, Type shopType,
			String manageBusinessType, String name, Date beginTime, Date endTime, Pageable page) {
		PageWrapper<Shop> shops = null;
		try {
			List<String> params = Lists.newArrayList();
			if (status != null) {
				params.add("status=" + status);
			}
			if (!Strings.isNullOrEmpty(siteCode)) {
				params.add("siteCode=" + siteCode);
			}
			if (!Strings.isNullOrEmpty(source)) {
				params.add("source=" + source);
			}
			if (!Strings.isNullOrEmpty(areaText)) {
				params.add("areaText=" + URLEncoder.encode(areaText, "UTF-8"));
			}
			if (shopType != null) {
				params.add("shopType=" + URLEncoder.encode(shopType.name(), "UTF-8"));
			}
			if (!Strings.isNullOrEmpty(manageBusinessType)) {
				params.add("manageBusinessType=" + URLEncoder.encode(manageBusinessType, "UTF-8"));
			}
			if (!Strings.isNullOrEmpty(name)) {
				params.add("name=" + URLEncoder.encode(name, "UTF-8"));
			}
			// if (!Strings.isNullOrEmpty(shopName)) {
			// params.add("shopName=" + URLEncoder.encode(shopName, "UTF-8"));
			// }
			if (beginTime != null) {
				params.add("beginTime=" + URLEncoder.encode(sdf.format(beginTime), "UTF-8"));
			}
			if (endTime != null) {
				params.add("endTime=" + URLEncoder.encode(sdf.format(endTime), "UTF-8"));
			}
			if (page != null) {
				params.add("page=" + page.getPageNumber());
				params.add("size=" + page.getPageSize());
				// params.add("size="+1);
			}
			Response response = get(crawlerServer + "shop/findByCondition"
					+ (params.isEmpty() ? "" : "?" + Joiner.on("&").join(params)));

			// System.out.println(response.returnContent().asString());

			String respStr = response.returnContent().asString();
			log.info("获取爬虫数据接口返回数据:{}", respStr);
			shops = objectMapper.readValue(respStr, new TypeReference<PageWrapper<Shop>>() {
			});
			//
			// PageWrapper<?>
			// pageWrapper=objectMapper.readValue(response.returnContent().asString(), new
			// TypeReference<PageWrapper<HashMap<?, ?>>>(){});
			// List<Map> shopMaps=(List<Map>)pageWrapper.getContent();
		} catch (Exception e) {
			log.error("读取数据异常", e);
		}
		// List<ShopDTO> shopDTO=shops.getContent();
		// List<ShopDTO> shopDTO=null;
		// List<Shop> shopList=new ArrayList<>();
		// shopDTO.forEach(s->{
		// Shop shop=new Shop();
		// shop.setName(s.getName());
		// shopList.add(shop);
		// });
		return new PageImpl<>(null == shops ? Lists.newArrayList() : shops.getContent(), page,
				shops == null ? 0 : shops.getTotalElements());
	}

	/**
	 * Get request
	 * 
	 * @param url
	 *            地址
	 * @return 响应
	 */
	private Response get(String url) {
		try {
			log.info("接口请求地址：{}", url);
			return Request.Get(url).socketTimeout(5000).connectTimeout(5000)
					// .addHeader("Authorization", "Basic Y3Jhd2xlci1hcGk6YzBuc3VtZXJAY3JAd2xlcg==")
					.execute();
		} catch (IOException e) {
			log.error("请求异常", e);
			return null;
		}
	}

	/**
	 * 商铺管理列表查询
	 */
	@Override
	public Page<Shop> findByCondition(CreateType createType, Long city, Long area, Long businessArea, Integer rentType,
			Type type, Long parentManageType, Long sonManageType, Integer onlineStatus, String name, String shopNumber,
			ShopAudit shopAudit, Date beginTime, Date endTime, Pageable page) {
		return shopRepository.findAll(new Specification<Shop>() {

			@Override
			public Predicate toPredicate(Root<Shop> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
				List<Predicate> predicates = new ArrayList<>();
				if (createType != null) {
					predicates.add(cb.and(cb.equal(root.get("createType"), createType)));
				}
				if (city != null) {
					predicates.add(cb.and(cb.equal(root.get("city"), city)));
				}
				if (area != null) {
					predicates.add(cb.and(cb.equal(root.get("area"), area)));
				}
				if (businessArea != null) {
					predicates.add(cb.and(cb.equal(root.get("businessArea"), businessArea)));
				}
				if (rentType != null) {
					predicates.add(cb.and(cb.equal(root.get("rentType"), rentType)));
				}
				if (type != null) {
					predicates.add(cb.and(cb.equal(root.get("type"), type)));
				}
				if (parentManageType != null) {
					predicates.add(cb.and(cb.equal(root.get("parentManageType"), parentManageType)));
				}
				if (sonManageType != null) {
					predicates.add(cb.and(cb.equal(root.get("sonManageType"), sonManageType)));
				}
				if (onlineStatus != null) {
					predicates.add(cb.and(cb.equal(root.get("onlineStatus"), onlineStatus)));
				}
				if (name != null) {
					predicates.add(cb.and(cb.equal(root.get("name"), name)));
				}
				if (shopNumber != null) {
					predicates.add(cb.and(cb.equal(root.get("shopNumber"), shopNumber)));
				}
				if (shopAudit != null) {
					predicates.add(cb.and(cb.equal(root.get("shopAudit"), shopAudit)));
				}
				if (beginTime != null) {
					predicates.add(cb.and(cb.greaterThanOrEqualTo(root.get("createTime"), beginTime)));
				}
				if (endTime != null) {
					predicates.add(cb.and(cb.lessThanOrEqualTo(root.get("createTime"), UpzlUtils.timeHelper(endTime))));
				}
				// predicates.add(cb.and(cb.notEqual((root.get("shopAudit")),
				// ShopAudit.审核未通过)));
				// return cb.and(predicates.toArray(new Predicate[predicates.size()]));
				// 商铺管理列表查询按商户编号倒叙排列
				// predicates.add(cb.and(cb.equal(root.get("isImport"), 1)));
				query.where(cb.and(predicates.toArray(new Predicate[predicates.size()])));
				query.orderBy(cb.desc(root.get("shopNumber")));
				return query.getRestriction();
			}
		}, page);
	}

	/**
	 * 审核查询
	 */
	@Override
	public Page<Shop> findByAuditCondition(CreateType createType, Long city, Long area, Long businessArea,
			Integer rentType, Type type, Long shopBusinessType, String name, String shopNumber, Date beginTime,
			Date endTime, Date claimBeginTime, Date claimEndTime, Date verifyBeginTime, Date verifyEndTime,
			Date auditBeginTime, Date auditEndTime, ShopAudit shopAudit, String verifyName, Pageable page,
			String sysAccount) {
		return shopRepository.findAll((root, query, cb) -> {
			List<Predicate> predicates = new ArrayList<>();
			if (createType != null) {
				predicates.add(cb.and(cb.equal(root.get("createType"), createType)));
			}
			if (city != null) {
				predicates.add(cb.and(cb.equal(root.get("city"), city)));
			}
			if (area != null) {
				predicates.add(cb.and(cb.equal(root.get("area"), area)));
			}
			if (businessArea != null) {
				predicates.add(cb.and(cb.equal(root.get("businessArea"), businessArea)));
			}
			if (rentType != null) {
				predicates.add(cb.and(cb.equal(root.get("rentType"), rentType)));
			}
			if (type != null) {
				predicates.add(cb.and(cb.equal(root.get("type"), type)));
			}
			if (shopBusinessType != null) {
				predicates.add(
						cb.equal(root.join("manageBusinessTypes"), shopBusinessTypeService.findOne(shopBusinessType)));
			}
			if (name != null) {
				predicates.add(cb.and(cb.equal(root.get("name"), name)));
			}
			if (shopNumber != null) {
				predicates.add(cb.and(cb.equal(root.get("shopNumber"), shopNumber)));
			}
			if (beginTime != null) {
				predicates.add(cb.and(cb.greaterThanOrEqualTo(root.get("createTime"), beginTime)));
			}
			if (endTime != null) {
				predicates.add(cb.and(cb.lessThanOrEqualTo(root.get("createTime"), UpzlUtils.timeHelper(endTime))));
			}
			if (claimBeginTime != null) {
				predicates.add(cb.and(cb.greaterThanOrEqualTo(root.get("claimTime"), claimBeginTime)));
			}
			if (claimEndTime != null) {
				predicates.add(cb.and(cb.lessThanOrEqualTo(root.get("claimTime"), UpzlUtils.timeHelper(claimEndTime))));
			}
			if (verifyBeginTime != null) {
				predicates.add(cb.and(cb.greaterThanOrEqualTo(root.get("verifyTime"), verifyBeginTime)));
			}
			if (verifyEndTime != null) {
				predicates
						.add(cb.and(cb.lessThanOrEqualTo(root.get("verifyTime"), UpzlUtils.timeHelper(verifyEndTime))));
			}
			if (auditBeginTime != null) {
				predicates.add(cb.and(cb.greaterThanOrEqualTo(root.get("auditTime"), auditBeginTime)));
			}
			if (auditEndTime != null) {
				predicates.add(cb.and(cb.lessThanOrEqualTo(root.get("auditTime"), UpzlUtils.timeHelper(auditEndTime))));
			}
			if (shopAudit != null) {
				predicates.add(cb.and(cb.equal(root.get("shopAudit"), shopAudit)));
			}
			if (verifyName != null) {
				predicates.add(cb.equal(root.join("verificationAccount").get("account"), verifyName));
			}
			if (!StringUtils.isEmpty(sysAccount)) {
				predicates.add(cb.equal(root.get("userCode"), sysAccount));
			}
			// 按倒叙查询审核、已通过、未通过列表
			query.where(cb.and(predicates.toArray(new Predicate[predicates.size()])));
			if (ShopAudit.审核已通过 == shopAudit || ShopAudit.审核未通过 == shopAudit) {
				query.orderBy(cb.desc(root.get("verifyTime")));
			} else {
				query.orderBy(cb.desc(root.get("id")));
			}
			return query.getRestriction();
		}, page);
	}

	/**
	 * 
	 */
	@Override
	public List<Shop> findAllX(CreateType createType, Long city, Long area, Long businessArea, Integer rentType,
			Type type, Long parentManageType, Long sonManageType, Integer onlineStatus, String name, String shopNumber,
			Date beginTime, Date endTime) {
		return shopRepository.findAll((root, query, cb) -> {
			List<Predicate> predicates = new ArrayList<>();
			if (createType != null) {
				predicates.add(cb.and(cb.equal(root.get("createType"), createType)));
			}
			if (city != null) {
				predicates.add(cb.and(cb.equal(root.get("city"), city)));
			}
			if (area != null) {
				predicates.add(cb.and(cb.equal(root.get("area"), area)));
			}
			if (businessArea != null) {
				predicates.add(cb.and(cb.equal(root.get("businessArea"), businessArea)));
			}
			if (rentType != null) {
				predicates.add(cb.and(cb.equal(root.get("rentType"), rentType)));
			}
			if (type != null) {
				predicates.add(cb.and(cb.equal(root.get("type"), type)));
			}
			if (parentManageType != null) {
				predicates.add(cb.and(cb.equal(root.get("parentManageType"), parentManageType)));
			}
			if (sonManageType != null) {
				predicates.add(cb.and(cb.equal(root.get("sonManageType"), sonManageType)));
			}
			if (onlineStatus != null) {
				predicates.add(cb.and(cb.equal(root.get("onlineStatus"), onlineStatus)));
			}
			if (name != null) {
				predicates.add(cb.and(cb.equal(root.get("name"), name)));
			}
			if (shopNumber != null) {
				predicates.add(cb.and(cb.equal(root.get("shopNumber"), shopNumber)));
			}

			predicates.add(cb.and(cb.equal(root.get("shopAudit"), ShopAudit.审核已通过)));

			if (beginTime != null) {
				predicates.add(cb.and(cb.greaterThanOrEqualTo(root.get("createTime"), beginTime)));
			}
			if (endTime != null) {
				predicates.add(cb.and(cb.lessThanOrEqualTo(root.get("createTime"), UpzlUtils.timeHelper(endTime))));
			}
			query.where(cb.and(predicates.toArray(new Predicate[predicates.size()])));
			query.orderBy(cb.desc(root.get("createTime")));
			return query.getRestriction();
		});
	}

	@Override
	public List<Shop> findByUserAccount(Long sid, Date nowTime) {
		return shopRepository.findAll(new Specification<Shop>() {

			@Override
			public Predicate toPredicate(Root<Shop> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
				List<Predicate> predicates = new ArrayList<>();
				if (sid != null) {
					predicates.add(cb.and(cb.equal(root.join("verificationAccount").get("id"), sid)));
				}

				if (nowTime != null) {
					predicates.add(cb.and(cb.greaterThanOrEqualTo(root.get("claimTime"), nowTime)));
				}
				if (nowTime != null) {
					predicates.add(cb.and(cb.lessThanOrEqualTo(root.get("claimTime"), UpzlUtils.timeHelper(nowTime))));
				}
				return cb.and(predicates.toArray(new Predicate[predicates.size()]));
			}
		});
	}

	@Override
	public Integer updateShopAudit(Long id, String shopAudit, String remark) {
		ShopAudit[] shopAudits = Shop.ShopAudit.values();
		Integer shopAuditIndex = null;
		for (int i = 0; i < shopAudits.length; i++) {
			if (shopAudit.equals(shopAudits[i].name())) {
				shopAuditIndex = i;
				break;
			}
		}
		return shopRepository.updateShopAudit(id, shopAuditIndex, remark);
	}

	/**
	 * 待核实查询
	 */
	@Override
	public Page<Shop> findByAuditConditions(CreateType createType, Long city, Long area, Long businessArea,
			Integer rentType, Type type, Long shopBusinessType, String name, String shopNumber, Date beginTime,
			Date endTime, Date claimBeginTime, Date claimEndTime, Date verifyBeginTime, Date verifyEndTime,
			Date auditBeginTime, Date auditEndTime, ShopFlow shopFlow, String verifyName, Pageable page,
			String sysAccount) {
		return shopRepository.findAll(new Specification<Shop>() {

			@Override
			public Predicate toPredicate(Root<Shop> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
				List<Predicate> predicates = new ArrayList<>();
				if (createType != null) {
					predicates.add(cb.and(cb.equal(root.get("createType"), createType)));
				}
				if (city != null) {
					predicates.add(cb.and(cb.equal(root.get("city"), city)));
				}
				if (area != null) {
					predicates.add(cb.and(cb.equal(root.get("area"), area)));
				}
				if (businessArea != null) {
					predicates.add(cb.and(cb.equal(root.get("businessArea"), businessArea)));
				}
				if (rentType != null) {
					predicates.add(cb.and(cb.equal(root.get("rentType"), rentType)));
				}
				if (type != null) {
					predicates.add(cb.and(cb.equal(root.get("type"), type)));
				}
				if (shopBusinessType != null) {
					predicates.add(cb.equal(root.join("manageBusinessTypes"),
							shopBusinessTypeService.findOne(shopBusinessType)));
				}
				if (name != null) {
					predicates.add(cb.and(cb.equal(root.get("name"), name)));
				}
				if (shopNumber != null) {
					predicates.add(cb.and(cb.equal(root.get("shopNumber"), shopNumber)));
				}
				if (beginTime != null) {
					predicates.add(cb.and(cb.greaterThanOrEqualTo(root.get("createTime"), beginTime)));
				}
				if (endTime != null) {
					predicates.add(cb.and(cb.lessThanOrEqualTo(root.get("createTime"), UpzlUtils.timeHelper(endTime))));
				}
				if (claimBeginTime != null) {
					predicates.add(cb.and(cb.greaterThanOrEqualTo(root.get("claimTime"), claimBeginTime)));
				}
				if (claimEndTime != null) {
					predicates.add(
							cb.and(cb.lessThanOrEqualTo(root.get("claimTime"), UpzlUtils.timeHelper(claimEndTime))));
				}
				if (verifyBeginTime != null) {
					predicates.add(cb.and(cb.greaterThanOrEqualTo(root.get("verifyTime"), verifyBeginTime)));
				}
				if (verifyEndTime != null) {
					predicates.add(
							cb.and(cb.lessThanOrEqualTo(root.get("verifyTime"), UpzlUtils.timeHelper(verifyEndTime))));
				}
				if (auditBeginTime != null) {
					predicates.add(cb.and(cb.greaterThanOrEqualTo(root.get("auditTime"), auditBeginTime)));
				}
				if (auditEndTime != null) {
					predicates.add(
							cb.and(cb.lessThanOrEqualTo(root.get("auditTime"), UpzlUtils.timeHelper(auditEndTime))));
				}
				if (shopFlow != null) {
					if (ShopFlow.待核实 == shopFlow) {
						predicates.add(cb.and(cb.or(cb.equal(root.get("shopFlow"), ShopFlow.待核实),
								cb.equal(root.get("shopFlow"), ShopFlow.核铺待维护),
								cb.equal(root.get("shopFlow"), ShopFlow.核铺无效))));
					} else {
						predicates.add(cb.and(cb.equal(root.get("shopFlow"), shopFlow)));
					}

				}
				if (verifyName != null) {
					predicates.add(cb.equal(root.join("verificationAccount").get("account"), verifyName));
				}
				if (!StringUtils.isEmpty(sysAccount)) {
					predicates.add(cb.equal(root.get("userCode"), sysAccount));
				}
				// 实现待核实列表数据按倒叙显示排列
				query.where(cb.and(predicates.toArray(new Predicate[predicates.size()])));
				query.orderBy(cb.desc(root.get("id")));
				return query.getRestriction();
			}
		}, page);
	}

	/**
	 * 回调
	 */
	@Override
	public void notifySucc(String site, Long id) {
		try {
			List<String> params = Lists.newArrayList();

			params.add("siteCode=" + site);

			params.add("id=" + id);
			String url = crawlerServer + "shop/callbackClaim"
					+ (params.isEmpty() ? "" : "?" + Joiner.on("&").join(params));
			get(url);
		} catch (Exception e) {
			log.error("通知异常", e);
		}

	}

	@Override
	public Shop findByPhone(String phone) {
		return shopRepository.findByPhone(phone);
	}

	@Autowired
	private AreaService areaService;

	public List<Shop> findByAppArea(String area,Pageable pgeable) {
		return shopRepository.findAll(new Specification<Shop>() {
			@Override
			public Predicate toPredicate(Root<Shop> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
				List<Predicate> predicates = new ArrayList<>();
				if (area != null) {
					predicates.add(cb.equal(root.join("area"), areaService.findByName(area)));
				}
				query.where(cb.and(predicates.toArray(new Predicate[predicates.size()])));
				return query.getRestriction();
			}
		});
	}

	@Override
	public List<Shop> findByAppShop(Long next, Pageable pageable) {
		return shopRepository.findAll(new Specification<Shop>() {
			@Override
			public Predicate toPredicate(Root<Shop> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
				List<Predicate> predicates = new ArrayList<>();
				if (next != null) {
					predicates.add(cb.and(cb.le(root.get("auditTime"),next)));
				}
				//predicates.add(cb.and(cb.equal(root.get("shopFlow"), ShopFlow.审核已通过)));
				predicates.add(cb.and(cb.equal(root.get("onlineStatus"),1)));
				query.where(cb.and(predicates.toArray(new Predicate[predicates.size()])));
				return query.getRestriction();
			}
		}, pageable).getContent();
	}
}